package com.swt.testdemo.controller;


import com.swt.testdemo.config.ResponseBean;
import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.service.SysCommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/19 9:56
 **/
@RestController
@RequestMapping("/sys/common")
@Api(tags = "系统公共接口")
@Slf4j
public class SysCommonController {


    @Autowired
    private SysCommonService sysCommonService;




    @ApiOperation("01 系统服务器地址信息 (完成)")
    @GetMapping(value = "/system-file-server")
    public ResponseEntity<ResponseBean> getSystemFileServer() {
        ResponseBean bean = sysCommonService.getSystemFileServer();
        return ResponseEntity.status(bean.getStatus()).body(bean);
    }


    @ApiOperation("02 通过country的编码获取省市县信息")
    @GetMapping("/dict/country-info")
    @ApiImplicitParam(name = "countyFullCode", value = "县/区全码", required = true, paramType = "query", dataType = "string", defaultValue = "110101")
    public ResponseEntity<ResponseBean> getDictCountryInfo(String countyFullCode){
        ResponseBean response = sysCommonService.getDictCountryInfo(countyFullCode);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

   @ApiOperation("03 获取省份字典")
   @GetMapping(value = "/dict/province-list")
   public ResponseEntity<ResponseBean> getDictProvinceList(){
       ResponseBean response = sysCommonService.getDictProvinceList();
       return ResponseEntity.status(response.getStatus()).body(response);

   }


    @ApiOperation("04 根据省份code获取所有的市字典")
    @GetMapping("/dict/province-city")
    @ApiImplicitParam(name = "provinceCode",value = "省份 code",required = true,paramType = "query",dataType = "String",defaultValue = "11")
    public ResponseEntity<ResponseBean> getDictProvinceCity(String provinceCode){
       ResponseBean response = sysCommonService.getDictProvinceCity(provinceCode);
       return ResponseEntity.status(response.getStatus()).body(response);


   }


    @ApiOperation("05 根据市code获取所有的县字典")
    @GetMapping(value = "/dict/city-county")
    @ApiImplicitParam(name = "cityFullCode",value = "市 code",required = true,paramType = "query",dataType = "String",defaultValue = "1101")
    public ResponseEntity<ResponseBean> getDictCityCounty(String cityFullCode){
        ResponseBean response = sysCommonService.getDictCityCounty(cityFullCode);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("06 刷新词典列表")
    @GetMapping(value = "/dict/refresh")
   public ResponseEntity<ResponseMessage> refreshDict(){
        ResponseMessage response = sysCommonService.refreshDict();
        return ResponseEntity.status(response.getStatus()).body(response);

    }


}
